#include common_scripts\utility;
#include maps\_statusutility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;

init()
{

//  Set DVARS
    maps\_dvar::statusDVARS();
    thread onPlayerConnect();
}

onPlayerConnect()
{
    level endon("game_ended");

    for(;;)
    {
        level waittill("connecting", player);

        player.ranks                        = [];
        player.ranks["rank_id"]             = undefined;
        player.ranks["rank_display"]        = undefined;

        player thread updateRankStatus();
        player thread onPlayerSpawned();
        player thread Connect();
        player thread HUD();
    }
}

updateRankStatus()
{
    self endon("disconnect");

    for(;;)
    {
        if(self hasStatus("developer"))
        {
            self.ranks["rank_id"] = 5;
            self.ranks["rank_display"] = "^0[^7Your Status^0: ^5Developer^0]";
            if(self hasStatus("admin") )
            {
                self.ranks["rank_id"] = 4;
                self.ranks["rank_display"] = "^0[^7Your Status^0: ^1Admin^0]";
                if(self hasStatus("moderator") )
                {
                    self.ranks["rank_id"] = 3;
                    self.ranks["rank_display"] = "^0[^7Your Status^0: ^2Moderator^0]";
                    if(self hasStatus("vip") )
                    {
                        self.ranks["rank_id"] = 2;
                        self.ranks["rank_display"] = "^0[^7Your Status^0: ^6VIP^0]";
                        if(self hasStatus("donator") )
                        {
                            self.ranks["rank_id"] = 1;
                            self.ranks["rank_display"] = "^0[^7Your Status^0: ^3Donator^0]";
                        }
                    }
                }
            }
        }
        else
        {
            self.ranks["rank_id"] = 0;
            self.ranks["rank_display"] = "^0[^7Your Status^0: ^7Player^0]";
        }

        wait 0.1;
    }
}

onPlayerSpawned()
{
    level endon("game_ended");
    self endon("disconnect");

    for(;;)
    {
        self waittill("spawned_player");

        while(!isDefined(self.ranks["rank_id"]))
            wait .1;

        switch( self.ranks["rank_id"] )
        {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        }

    }
}

HUD()
{
    self endon("death");
    self endon("killed_player");
    self endon("joined_spectators");
    self endon("disconnect");

    while(!isDefined(self.ranks["rank_display"]))
        wait .1;

    if (isDefined(level.ff_hud))
        level.ff_hud destroy();

    self.ff_hud = newClientHudElem(self);
    self.ff_hud.x = 7;
    self.ff_hud.y = 415;
    self.ff_hud.horzAlign = "left";
    self.ff_hud.vertAlign = "top";
    self.ff_hud.alignX = "left";
    self.ff_hud.alignY = "middle";
    self.ff_hud.alpha = 1;
    self.ff_hud.fontScale = 1.5;
    self.ff_hud.hidewheninmenu = true;
    self.ff_hud.color = (.99, .99, .75);
    self.ff_hud setText(self.ranks["rank_display"]);

    for(;;)
    {
        wait .1;

        self.ff_hud setText(self.ranks["rank_display"]);
    }
}

Connect()
{
    level endon("spawned_player");

    for(;;)
    {
        self waittill("spawned_player");
        self endon("death");
        myguid = self GetGuid();

        wait 0.5;
        self IPrintLn("^7Your GUID is ^0: ^5" + myguid + "^7");

        if(self hasStatus("developer"))
        {
            iprintlnbold("^7Developer ^5" + self.name + " ^7Has Entered the server.");
        }
        else
        {
            wait .1;
        }
        wait .1;
    }
}
